package cc.autoapi.pucong.auto.flow.provider.node.controller;

import cc.autoapi.pucong.auto.flow.core.root.entity.BatchDeleteIdDto;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowBaseController;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowExceptionHandler;
import cc.autoapi.pucong.auto.flow.core.root.utils.Res;
import cc.autoapi.pucong.auto.flow.provider.node.manager.NodeParamsManager;
import cc.autoapi.pucong.auto.flow.provider.node.entity.dto.NodeParamsAddDto;
import cc.autoapi.pucong.auto.flow.provider.node.entity.dto.NodeParamsUpdateDto;
import cc.autoapi.pucong.auto.flow.provider.node.entity.qo.NodeParamsQo;
import cc.autoapi.pucong.auto.flow.provider.node.entity.vo.NodeParamsVo;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author pucong
 * @description 节点参数信息 controller
 * @create 2024-09-23
 */
@RestController
@Validated
@RequestMapping("/node/nodeParams")
public class NodeParamsController extends AutoFlowBaseController implements AutoFlowExceptionHandler{

    @Resource
    private NodeParamsManager nodeParamsManager;

    @GetMapping("/getList")
    public Res<List<NodeParamsVo>> getList(NodeParamsQo dto) {
        List<NodeParamsVo> nodeParamsList = nodeParamsManager.getList(dto);
        return Res.ok(nodeParamsList);
    }

    @GetMapping("/getDetailById/{id}")
    public Res<NodeParamsVo> getDetailById(@PathVariable("id") String id) {
        NodeParamsVo nodeParamsDto = nodeParamsManager.getDetailById(id);
        return Res.ok(nodeParamsDto);
    }

    @PostMapping("/add")
    public Res<String> add(@RequestBody NodeParamsAddDto dto) {
        String id = nodeParamsManager.add(dto);
        return Res.ok(id);
    }

    @PostMapping("/updateById/{id}")
    public Res<Boolean> updateById(@PathVariable("id") String id,
                                   @RequestBody NodeParamsUpdateDto dto) {
        Boolean i = nodeParamsManager.updateById(id, dto);
        return Res.ok(i);
    }

    @DeleteMapping("/batchDeleteByIds")
    public Res<Boolean> batchDeleteByIds(BatchDeleteIdDto dto) {
        Boolean i = nodeParamsManager.batchDeleteByIds(dto.getIdList());
        return Res.ok(i);
    }
}
